package com.atguigu.admin.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * ClassName:LoginProtectInterceptor
 * Package:com.atguigu.admin.interceptor
 * Description:
 *
 * @Author 应永豪
 * @Create 2024/4/23 10:51
 * @Version 1.0
 */
@Component
public class LoginProtectInterceptor implements HandlerInterceptor {

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,Object handler) throws Exception{
        Object userInfo = request.getSession().getAttribute("userInfo");
        if (userInfo!=null){
//            放行
            return true;
        }else {
//            重定向回登录页
            response.sendRedirect(request.getContextPath()+"/index.html");
            return false;
        }

    }
}
